<template>
  <div class="box">
    <div class="article-page" v-if="list.length > 0">
      <div
        v-for="item in list"
        :key="item.id"
        @click="tiao(item.id)"
        class="article-item"
      >
        <div class="head">
          <img :src="item.creatorAvatar" alt="" />
          <div class="con">
            <p class="title">{{ item.stem }}</p>
            <p class="other">{{ item.creatorName }} | {{ item.createdAt }}</p>
          </div>
        </div>
        <div class="body">{{ item.content }}</div>
        <div class="foot">
          点赞 {{ item.likeCount }} | 浏览 {{ item.views }}
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
export default {
  name: 'article1',
  data () {
    return {
      list: []
    }
  },
  created () {
    this.send()

  },
  computed: {

  },
  methods: {
    send () {
      axios({
        url: 'https://mock.boxuegu.com/mock/3083/articles'
      }).then(res => {
        this.list = res.data.result.rows
        console.log(this.list);
      })
    },
    tiao (id) {
      console.log(1);
      this.$router.push({
        name: 'detail',
        params: { id }
      })
    }


  },
  //keep alive对应的两个钩子函数
  activated () {
    console.log('artilce===页面进入时触发');
  },
  deactivated () {
    console.log('artilce===离开页面时触发');
    console.log(document.documentElement.scrollHeight);

  }

}
</script>
<style lang='less'  scoped>
.article-page {
  margin-bottom: 50px;
  .my-nav {
    height: 44px;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    z-index: 999;
    background: #fff;
    display: flex;
    align-items: center;
    > a {
      color: #999;
      font-size: 14px;
      line-height: 44px;
      margin-left: 20px;
      position: relative;
      transition: all 0.3s;
      &::after {
        content: '';
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: 0;
        width: 0;
        height: 2px;
        background: #222;
        transition: all 0.3s;
      }
      &.active {
        color: #222;
        &::after {
          width: 14px;
        }
      }
    }
    .logo {
      flex: 1;
      display: flex;
      justify-content: flex-end;
      > img {
        width: 64px;
        height: 28px;
        display: block;
        margin-right: 10px;
      }
    }
  }
}
.article-item {
  background-color: #fff;
  padding: 10px;
  margin-bottom: 20px;
  .head {
    display: flex;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
    .con {
      flex: 1;
      overflow: hidden;
      padding-left: 10px;
      p {
        margin: 0;
        line-height: 1.5;
        &.title {
          width: 280px;
        }
        &.other {
          font-size: 10px;
          color: #999;
        }
      }
    }
  }
  .body {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    margin-top: 10px;
  }
  .foot {
    font-size: 12px;
    color: #999;
    margin-top: 10px;
  }
}
</style>
